﻿using stdCall.File;
using stdCall.Models;
using stdCall.Resource;
using System;
using System.Collections;
using System.Windows.Forms;

namespace stdCall.History
{
    /// <summary>
    /// 历史记录类
    /// </summary>
    class CurrentHistory
    {
        public static ArrayList unluckSavingCalls = new ArrayList();

        /// <summary>
        /// 保存历史记录到ResouseLoader.FileUCSPath
        /// </summary>
        /// <returns></returns>
        public bool save(){
            new FileHelper().closeFile();
            new FileHelper().openWriteFile(ResourseLoader.FileUCSPath);
            bool flag = true;
            foreach (unluckSavingCall uc in unluckSavingCalls)
            {
                if (!uc.Saveflag)
                {
                    try
                    {
                        new FileHelper().writeSingleData(uc.Studentid);
                        new FileHelper().writeSingleData(uc.Star.ToString());
                        new FileHelper().writeSingleData(uc.CourseID.ToString());
                        uc.Saveflag = true;
                    }
                    catch (System.Exception ex)
                    {
                        flag = false;
                        ThreadExceptionDialog warnDialog = new ThreadExceptionDialog(ex);
                        warnDialog.ShowDialog();
                        uc.Saveflag = false;
                    }
                }
            }
            new FileHelper().closeFile();
            return flag;
        }

        /// <summary>
        /// 添加一个点名
        /// </summary>
        /// <param name="studentid"></param>
        /// <param name="star"></param>
        /// <param name="courseNum"></param>
        public void addUnluckyCall(String studentid, int star, int courseNum)
        {
            unluckSavingCalls.Add(new unluckSavingCall(studentid, star, courseNum));
        }

        public void getHistoryCalls()
        {

        }
        /// <summary>
        /// 删除历史记录，未实现
        /// </summary>
        /// <param name="studentnum"></param>
        public void delCallByStdNum(int studentnum)
        {

        }

        

    }
}
